package com.kefu.call.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.basic.model.BasicStatusConfig;
import com.kefu.call.model.CallMakeCall;
import com.kefu.call.model.CallStart;
import com.kefu.call.model.CallUserStatus;
import com.kefu.call.service.CallConnectService;
import com.kefu.call.service.CallStatisticsService;
import com.kefu.call.vo.*;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Api(tags = "呼叫统计")
@RestController
@RequestMapping("call/statistics/")
public class CallStatisticsController extends AbstractBaseController {
    @Resource
    private CallConnectService callConnectService;
    @Resource
    private CallStatisticsService callStatisticsService;

    @PostMapping("callRecordList")
    @ApiOperation(value = "呼出纪录", notes = "呼出纪录")
    public Result<Page<CallMakeCall>> callMakeCallList(@Validated @RequestBody CallMakeCallSearchVo search) {
        Page<CallMakeCall> page = callConnectService.callMakeCallList(search);
        return ResultGenerator.genSuccessResult(page);
    }

    @PostMapping("callStartList")
    @ApiOperation(value = "呼入纪录", notes = "呼入纪录")
    public Result<Page<CallStart>> callStartList(@Validated @RequestBody CallStartSearchVo search) {
        Page<CallStart> page = callConnectService.callStartList(search);
        return ResultGenerator.genSuccessResult(page);
    }

    @PostMapping("exportCallRecord")
    @ApiOperation(value = "导出外呼纪录", notes = "导出外呼纪录")
    public void exportCallRecord(@Validated @RequestBody CallMakeCallSearchVo searchVo, HttpServletResponse response) throws IOException {
        callConnectService.exportCallRecord(searchVo, response);
    }

    @PostMapping("exportCallStartRecord")
    @ApiOperation(value = "导出呼入纪录", notes = "导出呼入纪录")
    public void exportCallStartRecord(@Validated @RequestBody CallStartSearchVo searchVo, HttpServletResponse response) throws IOException {
        callConnectService.exportCallStartRecord(searchVo, response);
    }

    @PostMapping("exportCallStartFailRecord")
    @ApiOperation(value = "导出呼入呼损纪录", notes = "导出呼入呼损纪录")
    public void exportCallStartFailRecord(@Validated @RequestBody CallStartSearchVo searchVo, HttpServletResponse response) throws IOException {
        callConnectService.exportCallStartFailRecord(searchVo, response);
    }

    @PostMapping("overview")
    @ApiOperation(value = "通话概览统计", notes = "通话概览统计")
    public Result<CallOverviewVo> callOverview(@Validated @RequestBody CallOverviewSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callOverview(param));
    }

    @PostMapping("overviewDayAndMonth")
    @ApiOperation(value = "通话概览按类型统计", notes = "通话概览按类型统计")
    public Result<List<CallOverviewVo>> callOverviewType(@Validated @RequestBody CallOverviewSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callOverviewList(param));
    }

    @PostMapping("overviewDayAndMonthExport")
    @ApiOperation(value = "通话概览按类型统计导出", notes = "通话概览按类型统计导出")
    public void callOverviewTypeExport(@Validated @RequestBody CallOverviewSearchVo param,HttpServletResponse response) throws IOException {
         callStatisticsService.callOverviewListExport(param,response);
    }

    @PostMapping("overviewTrend")
    @ApiOperation(value = "通话概览趋势", notes = "通话概览趋势")
    public Result<List<CallOverviewVo>> callOverviewTrend(@Validated @RequestBody CallOverviewSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callOverviewTrend(param));
    }

    @PostMapping("callAgentWorkloadList")
    @ApiOperation(value = "坐席工作量统计", notes = "坐席工作量统计")
    public Result<Page<CallAgentWorkLoadVo>> callAgentWorkloadList(@Validated @RequestBody CallAgentWorkLoadSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callWorkloadList(param));
    }

    @PostMapping("exportCallAgentWorkload")
    @ApiOperation(value = "坐席工作量统计导出", notes = "坐席工作量统计导出")
    public void exportCallAgentWorkload(@Validated @RequestBody CallAgentWorkLoadSearchVo param, HttpServletResponse response) throws IOException {
        callStatisticsService.exportCallAgentWorkload(param, response);
    }

    @PostMapping("callAgentStatusTitle")
    @ApiOperation(value = "坐席状态统计动态表头", notes = "坐席状态统计动态表头")
    public Result<List<BasicStatusConfig>> callAgentStatusTitle() {
        return ResultGenerator.genSuccessResult(callStatisticsService.callAgentStatusTitle());
    }

    @PostMapping("exportCallAgentStatusRpt")
    @ApiOperation(value = "坐席状态统计导出", notes = "坐席状态统计导出")
    public void exportCallAgentStatusRpt(@Validated @RequestBody CallAgentWorkLoadSearchVo param, HttpServletResponse response) throws IOException {
        callStatisticsService.exportCallAgentStatusRpt(param, response);
    }

    @PostMapping("callSkillsetsWorkloadList")
    @ApiOperation(value = "技能组工作量统计", notes = "技能组工作量统计")
    public Result<List<CallSkillsetsWorkLoadVo>> callSkillsetsWorkloadList(@Validated @RequestBody CallSkillsetsWorkloadSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callSkillsetsWorkloadList(param));
    }

    @PostMapping("exportCallSkillsetsWorkload")
    @ApiOperation(value = "技能组工作量统计导出", notes = "技能组工作量统计导出")
    public void exportCallSkillsetsWorkload(@Validated @RequestBody CallSkillsetsWorkloadSearchVo param, HttpServletResponse response) throws IOException {
        callStatisticsService.exportCallSkillsetsWorkload(param, response);
    }

    @PostMapping("callNumberStatistics")
    @ApiOperation(value = "外呼号码统计", notes = "外呼号码统计")
    public Result<List<CallNumberStatisticsVo>> callNumberStatistics(@RequestBody CallNumberStatisticsSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callNumber(param));
    }

    @PostMapping("callNumberStatisticsExport")
    @ApiOperation(value = "外呼号码统计导出", notes = "外呼号码统计导出")
    public void callNumberStatisticsExport(@RequestBody CallNumberStatisticsSearchVo param, HttpServletResponse response) throws IOException {
        callStatisticsService.numberExport(param, response);
    }

    @PostMapping("callAgentStatusLog")
    @ApiOperation(value = "坐席状态统计日志", notes = "坐席状态统计日志")
    public Result<Page<CallAgentStatusVo>> callAgentStatusLog(@Validated @RequestBody CallAgentStatusSearchVo param) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callAgentStatusList(param));
    }

    @PostMapping("exportCallAgentStatusLog")
    @ApiOperation(value = "坐席状态统计日志导出", notes = "坐席状态统计日志导出")
    public void exportCallAgentStatusLog(@Validated @RequestBody CallAgentStatusSearchVo param, HttpServletResponse response) throws IOException {
        callStatisticsService.exportCallAgentStatusLog(param, response);
    }

    @PostMapping("callUserStatus")
    @ApiOperation(value = "坐席实时状态", notes = "坐席实时状态")
    public Result<List<CallUserStatus>> callUserStatus(@Validated @RequestBody CallUserStatusSearchVo searchVo) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callUserStatus(searchVo));
    }

    @PostMapping("callUserStatus/v2")
    @ApiOperation(value = "坐席实时状态", notes = "坐席实时状态(v2)")
    public Result<CallUserStatusWrapper> callUserStatus_v2(@Validated @RequestBody CallUserStatusSearchVo searchVo) {
        return ResultGenerator.genSuccessResult(callStatisticsService.callUserStatus_v2(searchVo));
    }

    @PostMapping("callQueueGroup")
    @ApiOperation(value = "技能组实时排队", notes = "技能组实时排队")
    public Result<List<CallQueueGroup>> callQueueGroup() {
        return ResultGenerator.genSuccessResult(callStatisticsService.callQueueGroup());
    }
}